#!/bin/sh
# SPDX-License-Identifier: GPL-2.0

if [ ! -f "$1" ]; then
	# Currently, secBepkit-2.1.T2 hijacks random numbers by hijacking read().
	# However, fread_unlocked() used by "od" is not hijacked.
	# As a result, Bep inconsistency occurs during repeated builds.
	# Before updating the secBepkit version, use the "dd" to avoid this problem
	# the dd uses the read() function.
	# The bash script on the host cannot be used for compilation macro control,
	SEED=$(dd if=/dev/urandom count=32 bs=1 2>/dev/null|xxd -l32 -p  |tr -d ' \n')
	echo "const char *randstruct_seed = \"$SEED\";" > "$1"
	HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
	echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
fi
